<!-- 修改说明：多仓库修改  t  2019-11-13
	15-23	支持多仓库：从session中获取仓库id
-->
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>邮件推送记录</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
<!-- ******************************多仓库修改  t  2019-11-13 开始*************************** -->
	<!-- 从session中获取仓库id -->
	<% Long warehouseId =  (Long)request.getSession().getAttribute("warehouse_id"); 
	  String warehouse_id = "";
		if(warehouseId != null){
		  warehouse_id = String.valueOf(warehouseId);
	  }
	%>
<!-- ******************************多仓库修改  t  2019-11-13 结束*************************** -->
</head>
<body class="layui-anim layui-anim-up">
	<!-- ******************************多仓库修改  t  2019-11-13 开始*************************** -->
	<!-- 利用全局仓库id的input保存session中仓库id -->
	<input id="warehouse_id" hidden="hidden" value="<%=warehouse_id%>">
	<!-- ******************************多仓库修改  t  2019-11-13 结束*************************** -->	
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>邮件推送记录</cite>
        </a>
      </span>
    </div>
    <div class="x-body">
      <div style="margin-bottom: 18px">
		<div class="layui-inline">
			<table>
				<tr>
					<td>
						<div class="layui-form" style="width: 185px">
							<select style="width: 285px" class="" name="keyword" id="keyword" lay-filter="keyword">
								<option value="">请选择供应商</option>
								<c:forEach items="${allCustomerList }" var="customer">
									<option value="${customer.id}">${customer.customer_name }</option>
								</c:forEach>
							</select>
							<input type="hidden" id="customerId" value="${customer_id}">
						</div>
					</td>
					<td>
						<!-- <input class="layui-input" name="keyword02" id="keyword02" placeholder="请输入操作名称" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px"> -->
						<div class="layui-form" style="width: 180px; margin-left: 10px">
							<select style="width: 180px" id="keyword02">
								<option value="">请选择操作名称</option>
								<option>入库</option>
								<option>出库</option>
							</select>
						</div>
					</td>
					<td>
						<input class="layui-input" name="keyword01" id="keyword01" placeholder="请输入邮件内容" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
					</td>
					<td>
						<input class="layui-input" id="startTime" placeholder="请输入开始时间" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
						-<input class="layui-input" id="endTime" placeholder="请输入结束时间" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px"> 
					</td>
				</tr>
			</table>
		</div>
		<button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon">&#xe615;</i>检索</button>
		<button class="layui-btn layui-btn-normal" data-type="upSendQQMail_num">编辑满足数量<span id="sendQQMail_num"></span></button>
	  </div>
	  <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
	</div>
<div id="addDivID" hidden="hidden">
		<form class="layui-form" id="addFormID">
			<br>
				<label class="layui-form-label">满足数量</label></td>
				<input class="layui-input" id="sendQQMailNum" lay-verify="sendQQMailNum" style="width: 280px;display:inline;">
				<span class="xing"></span>
			<br>
			<br>
			<button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="addForm" style="margin-left:140px;">立即提交</button>
			&emsp;&emsp;&emsp;&emsp;
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</form>
    </div>
	<script type="text/javascript">
        var table;
		layui.use(['table','layer','upload','form','laydate'], function(){
			table = layui.table;
			var layer = layui.layer;
			var form = layui.form;
			
			var laydate = layui.laydate;
			
			//日期时间范围
			var minListDate = "1000-01-01 00:00:00";//最小可选时间，例：1990-02-01
		    var maxListDate = "3000-12-31 23:59:59";//最大可选时间，例：2200-12-31   
		    var enddate = laydate.render({
		        elem: "#endTime",
		        format: 'yyyy-MM-dd HH:mm:ss',
		        type: 'datetime',
		        min: minListDate,
		        max: maxListDate,
		        done: function (val, date) {
		            if (date && date.year){
		            	//设置结束时间 设置开始时间的最大值为结束时间
		                begindate.config.max = {
		                    year: date.year,
		                    month: date.month - 1,//必须减1才是正确值
		                    date: date.date,
		                    hours: date.hours,
		                    minutes: date.minutes,
		                    seconds: date.seconds
		                };
		            }else {
		            	//清除结束值    设置开始时间最大值
		                var dateInit = new Date(maxListDate.replace(/-/g, "/"));
		                begindate.config.max = {
		                    year: dateInit.getFullYear(),
		                    month: dateInit.getMonth(),
		                    date: dateInit.getDate(),
		                    hours: dateInit.getHours(),
		                    minutes: dateInit.getMinutes(),
		                    seconds: dateInit.getSeconds()
		                };
		            }
		        }
		    });
		    var begindate = laydate.render({
		        elem: "#startTime",
		        format: 'yyyy-MM-dd HH:mm:ss',
		        type: 'datetime',
		        min: minListDate,
		        max: maxListDate,
		        done: function (val, date) {
		            if (date && date.year){
		            	//设置开始时间 设置结束时间的最小值为开始时间
		                enddate.config.min = {
		                    year: date.year,
		                    month: date.month - 1,
		                    date: date.date,
		                    hours: date.hours,
		                    minutes: date.minutes,
		                    seconds: date.seconds
		                };
		            }else {
		            	//清除开始值 ，设置结束值最小值
		                var dateInit = new Date(minListDate.replace(/-/g, "/"));
		                enddate.config.min = {
		                    year: dateInit.getFullYear(),
		                    month: dateInit.getMonth(),
		                    date: dateInit.getDate(),
		                    hours: dateInit.getHours(),
		                    minutes: dateInit.getMinutes(),
		                    seconds: dateInit.getSeconds()
		                };
		            }
		        }
		    });
			
			var $ = layui.jquery, active = {
				reload:function () {
					var keyword = $.trim($("#keyword").val());
					var keyword01 = $.trim($("#keyword01").val());
	                var keyword02 = $.trim($("#keyword02").val());
	                var tuisongtime = "";
	                var startTime = $.trim($("#startTime").val());
					if(startTime != null && startTime != ""){
						var tuisongtime = tuisongtime + " and e.receive_date >= '"+startTime+"' ";
					}
					var endTime = $.trim($("#endTime").val());
					if(endTime != null && endTime != ""){
						var tuisongtime = tuisongtime + " and e.receive_date <= '"+endTime+"' ";
					}
					/* ******************************多仓库修改  t  2019-11-13 开始*************************** */
					//判断全局仓库id是否为空  不为空加入查询条件
					var warehouse_id = $.trim($("#warehouse_id").val());
					if(warehouse_id != null && warehouse_id != ""){
						var tuisongtime = tuisongtime + " and e.warehouse_id = '"+warehouse_id+"' ";
					}
					/* ******************************多仓库修改  t  2019-11-13 结束*************************** */
					table.reload('tableList',{
						method:'get'
						,where:{
							receivePeopleId:keyword
							,emailContent:keyword01
	                        ,operate:keyword02
	                        ,receiveDate:tuisongtime
						}
						,page: {
		                    curr: 1//重新从第 1 页开始
		                }
					});
				},
				upSendQQMail_num:function () {
					layer.open({
						  type: 1 							//Page层类型
						  ,area: ['500px', '200px'] 	//宽  高
						  ,title: '修改邮件发送满足数量'
						  ,shade: 0.6 						//遮罩透明度
						  ,maxmin: true 					//允许全屏最小化
						  ,anim: 1 							//0-6的动画形式，-1不开启
						  ,content: $('#addDivID')
		                  ,end: function () {
		                      var formDiv = document.getElementById('addDivID');
		                      formDiv.style.display = '';
		                  }
		                  ,success: function(){
		                	  //需拆箱数量
		                      $("#sendQQMailNum").val("")
		                      form.render();
		                    }
						});
				}
			}
			$('.layui-btn').on('click', function(){
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
			//给发送数量赋值
			fzSendQQMail_num()
			
			var customerId = $.trim($("#customerId").val());
			if(customerId != null && customerId != ""){
				$("#keyword").val(customerId)
				$('#keyword').attr("disabled",true)
				form.render();
			}
			var keyword = $.trim($("#keyword").val());
			/* ******************************多仓库修改  t  2019-11-11 开始*************************** */
			var tuisongtime = ""
			//判断全局仓库id是否为空  不为空加入查询条件
			var warehouse_id = $.trim($("#warehouse_id").val());
			if(warehouse_id != null && warehouse_id != ""){
				tuisongtime = tuisongtime + " and e.warehouse_id = '"+warehouse_id+"' ";
			}
			/* ******************************多仓库修改  t  2019-11-11 结束*************************** */
			table.render({
				elem: '#tableList'
                ,url:'${pageContext.request.contextPath }/emailRecord/list.do'
               	,where:{
					receivePeopleId:keyword
					,receiveDate:tuisongtime
				}
                ,toolbar: '#toolbar'
				,title: 'machineList'
				,limits:[10,20,30]
                ,defaultToolbar:['filter', 'print']
				,request: {   //如果无需自定义请求参数，可不加该参数
	                pageName: 'page' //页码的参数名称，默认：page
	                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
	            }
	            ,response: {   //如果无需自定义数据响应名称，可不加该参数
	                countName: 'total' //规定数据总数的字段名称，默认：count
	                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
	            }
				,cols: [
		                [{
		                    type: 'checkbox',
		                    fixed: 'left'
		                }, {
		                	field:'id',
		                	title:'序号', 
		                	sort: true,
		                	width: 60,
		                	type:'numbers',
		                	align:'center'
		                } , {
		                    field: 'operate',
		                    title: '操作名称',
		                    align:'center',
		                } , {
		                    field: 'receivePeopleId',
		                    title: '邮件接收人',
		                    align:'center',
		                    templet: function (row){
		                    	var value = "";
		                    	if(null != row.customer){
		                    		value = row.customer.customer_name;
	                            }
                                return value;
	                        },
		                } , {
		                    field: 'emailContent',
		                    title: '邮件内容',
		                    align:'center',
		                } , {
		                    field: 'receiveDate',
		                    title: '推送时间',
		                    align:'center',
		                    templet: function(d){
	                    		return changeDateFormat(d.receiveDate)
	                    }
		                    
		                    
		                } , {
		                    field: 'remark',
		                    title: '是否发送',
		                    align:'center',
		                    templet: function (row){
		                    	var value = "否";
		                    	if(1 == row.remark){
		                    		value = "是";
	                            }
                                return value;
	                        },
		                }
		                ]
		               ]
				,page: true
				,done : function(){
	                $('th').css({
	                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
	                    //'font-size': 10,
	                })
	            }
			});
			
        	
        	
	        table.on('row(tableList)', function(obj){
	        	if(obj.checked == true && obj.type == 'all'){
	                //点击全选
	                $('.layui-table-body table.layui-table tbody tr').addClass('layui-table-click');
	            }else if(obj.checked == false && obj.type == 'all'){
	                //点击全不选
	                $('.layui-table-body table.layui-table tbody tr').removeClass('layui-table-click');
	            }else if(obj.checked == true && obj.type == 'one'){
	                //点击单行
	                if(obj.checked == true){
	                    obj.tr.addClass('layui-table-click');
	                }else{
	                    obj.tr.removeClass('layui-table-click');
	                }
	            }else if(obj.checked == false && obj.type == 'one'){
	                //点击全选之后点击单行
	                if(obj.tr.hasClass('layui-table-click')){
	                    obj.tr.removeClass('layui-table-click');
	                }
	            }
	        });
	        
	        
	        /**
			 * 新增表单校验
			 */
			form.verify({
	          	//value：表单的值、item：表单的DOM对象
	            sendQQMailNum: function(value, item){
	            	var value = $.trim(value)
	            	var re = /^[1-9]\d*$/;
	            	if(value == '' || value == null){
	                    return '不能为空';
	                }else if(value != '' && value != null && !re.test(value)){
	                    return '请输入正整数';
	                } 
	            },
			});
	        
			/**
			 * 通用表单提交(AJAX方式)(新增)
			 */
			form.on('submit(addForm)', function (data) {
				var index = layer.load(1, {
	        	    shade: [0.1,'#000'] //0.1透明度的背景
	        	});
				var sendQQMailNum = $.trim($("#sendQQMailNum").val())
				upSendQQMail_num(sendQQMailNum)
				layer.closeAll();
				return false;
			});
		});
		
		//获取当前时间生成的编码
	   	function curentTimeNumber() {
	   		var now=new Date();
	   		var year = now.getFullYear();       //年
	   	    var month = now.getMonth() + 1;     //月
	   	    var day = now.getDate();            //日
	   	 	var hours = now.getHours(); //获取当前小时数(0-23)
		   	var minutes = now.getMinutes(); //获取当前分钟数(0-59)
		   	var seconds = now.getSeconds(); //获取当前秒数(0-59)
	   	    //var mill=now.getMilliseconds();
	   	    var time=year+""+add0(month)+""+add0(day)+""+add0(hours)+""+add0(minutes)+""+add0(seconds);
	   		return time;
	   	}
	    //获取当前日期
	   	function curentTime() {
	   		var now=new Date();
	   		var year = now.getFullYear();       //年
	   	    var month = now.getMonth() + 1;     //月
	   	    var day = now.getDate();            //日
	   	    var time=year+"-"+add0(month)+"-"+add0(day);
	   		return time;
	   	}
	   	function add0(m){return m<10?'0'+m:m }
		toastrStyle()
	   	function fzSendQQMail_num(){
			$.ajax({
                type:'post',
                url:'${pageContext.request.contextPath }/sendQQMail_num/findSendQQMail_num.do',
                success:function(data){
					$("#sendQQMail_num").html(data)
                }
            })
		}
	   	function upSendQQMail_num(sendQQMailNum){
	   		$.ajax({
                type:'post',
                url:'${pageContext.request.contextPath }/sendQQMail_num/upSendQQMail_num.do',
                data:{"sendQQMailNum":sendQQMailNum},
                success:function(data){
                    if(data>0){
                        toastr.success("修改成功！");
                        fzSendQQMail_num()
                    }else{
                        toastr.warning("修改失败！");
                    }
                }

            })
		}
	    function changeDateFormat(timestamp) {
	    	if (timestamp == '') {
				return '';
			} else {
				var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				Y = date.getFullYear() + '-';
				M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
				D = (date.getDate()+1 < 10 ? '0'+(date.getDate()) : date.getDate())+ '      ';
				H = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours())+ ':';
	            MI= (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes())+':';
	            S = (date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds());
					
					return Y+M+D+H+MI+S;
			
			}
	    }
	</script>
</body>
</html>